import request from '@/utils/request'

/**
 * 注册接口
 * @returns
 */
export const regesterAPI = ({ username, password }) => {
  return request({
    url: '/api/regester',
    method: 'post',
    data: {
      username,
      password
    }
  })
}

// 登录接口
export const loginAPI = ({ username, password, usertype }) => {
  return request({
    url: '/api/login',
    method: 'post',
    data: {
      username,
      password,
      usertype
    }
    // headers: {
    //   'Content-Type': 'application/x-www-form-urlencoded'
    // }
  })
}

/**
 * 获取个人信息
 * @returns Promise Object
 */
export const getuserinfoAPI = () => {
  return request({
    method: 'get',
    url: '/my/userinfo'
  })
}

/**
 * 修改密码
 * @param {*} param0
 * @returns Promise Object
 */
export const changepasswordAPI = ({ oldPwd, newPwd }) => {
  return request({
    method: 'post',
    url: '/my/updatepwd',
    data: {
      oldPwd,
      newPwd
    }
  })
}
// 更新用户头像
export const updateavatarAPI = (user_pic) => {
  return request({
    method: 'post',
    url: '/my/update/avatar',
    data: {
      user_pic
    }
  })
}
/**
 * 更新个人信息
 * @param {*} param0
 * @returns Promise Object
 */
export const updateuserinfoapi = ({ nickname, email }) => {
  return request({
    method: 'post',
    url: '/my/userinfo',
    data: {
      nickname,
      email
    }
  })
}

// 用户发布商品信息
export const userpublishAPI = ({ product_name, detail, price, product_img, product_num, category, security }) => {
  return request({
    method: 'post',
    url: '/my/userpublish',
    data: {
      product_name,
      detail,
      price,
      product_img,
      product_num,
      category,
      security
    }
  })
}

// 获取用户发布审核通过的商品
export const getuserPublishAPI = () => {
  return request({
    method: 'get',
    url: '/my/getuserproduct'
  })
}

// 获取用户发布待审核的商品
export const getisauditstoreAPI = () => {
  return request({
    method: 'get',
    url: '/my/getuserproductidaudit'
  })
}

// 获取用户发布审核未通过的商品
export const getnoauditstoreAPI = () => {
  return request({
    method: 'get',
    url: '/my/getuserproductaddreason'
  })
}

/**
 * 获取商品分类
 * @returns promise
 */
export const getcategoryAPI = () => {
  return request({
    url: '/admin/getcategory'
  })
}

/**
 * 根据分类来获取商品
 * @param {*} category
 * @returns Promise Onject
 */
export const getstoreBycateAPI = (category) => {
  return request({
    method: 'post',
    url: '/admin/storeinfobycategory',
    data: {
      category
    }
  })
}

/**
 * 根据关键词查询商品信息
 * @param {*} keyword
 * @returns Promise Object
 */
export const getstoreinfoBykeywordAPI = (keyword) => {
  return request({
    method: 'post',
    url: '/admin/getstoreinfobykeyword',
    data: {
      keyword
    }
  })
}

/**
 * 根据id查看商品详情
 * @param {*} id
 * @returns Promise Object
 */
export const getstoreByid = (id) => {
  return request({
    method: 'post',
    url: '/admin/storeinfobyid',
    data: {
      id
    }
  })
}

// 收藏与取消收藏商品
export const starStoreAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/starstore',
    data: {
      id
    }
  })
}
// 加入购物车
export const addshoppingcarAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/shoppingcar',
    data: {
      id
    }
  })
}
// 获取购物车商品
export const getShoopingcarAPI = () => {
  return request({
    method: 'get',
    url: '/admin//getshoppingcarstore'
  })
}
// 增加购物车数量
export const addshoppingAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/addshopping',
    data: {
      id
    }
  })
}
// 减少购物车数量
export const lowshoppingAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/lowshopping',
    data: {
      id
    }
  })
}
// 从购物车移除
export const removeshoppingcarAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/removeshoppingcar',
    data: {
      id
    }
  })
}
/**
 * 删除商品分类 - 根据id
 * @param {id} id
 * @returns promise对象
 */
export const delcategoryAPI = (id) => {
  return request({
    url: '/admin/delcategory',
    method: 'delete',
    data: {
      id
    }
  })
}

/**
 * 修改商品分类
 * @param {id,cate_name,cate_alias} param0
 * @returns promise对象
 */
export const updatecategoryAPI = ({ id, cate_name, cate_alias }) => {
  return request({
    method: 'post',
    url: '/admin/updatecategory',
    data: {
      id,
      cate_name,
      cate_alias
    }
  })
}

/**
 * 添加分类
 * @param {cate_name,cate_alias} param0
 * @returns Promise Object
 */
export const addcategoryAPI = ({ cate_name, cate_alias }) => {
  return request({
    method: 'post',
    url: '/admin/addcategory',
    data: {
      cate_name,
      cate_alias
    }
  })
}

/**
 * 发布商品信息
 * @param {*} param0
 * @returns
 */
export const addstoreinfoAPI = ({ product_name, detail, price, product_img, product_num, category }) => {
  return request({
    method: 'post',
    url: '/admin/publishinfo',
    data: {
      product_name,
      detail,
      price,
      product_img,
      product_num,
      category
    }
  })
}

/**
 * 编辑商品信息
 * @param {*} param0
 * @returns Promise Object
 */
export const updatestoreinfoAPI = ({ product_name, detail, price, product_img, product_num, category, id }) => {
  return request({
    method: 'post',
    url: '/admin/updatestoreinfo',
    data: {
      product_name,
      detail,
      price,
      product_img,
      product_num,
      category,
      id
    }
  })
}

/**
 * 设置热门推荐
 * @param {*} param0
 * @returns Promise Object
 */
export const setHotAPI = (hot, id) => {
  return request({
    method: 'post',
    url: '/admin/sethot',
    data: {
      hot,
      id
    }
  })
}

/**
 * 获取热门商品
 * @returns Promise Object
 */
export const getHotstoreAPI = () => {
  return request({
    method: 'get',
    url: '/admin/gethotstore'
  })
}

/**
 * 获取商品信息
 * @returns Promise对象
 */
export const getstoreinfoAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getstoreinfo'
  })
}
// 查询待审核商品
export const getstoreinfoauditAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getstoreinfoaudit'
  })
}
// 通过审核
export const isauditAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/isaudit',
    data: {
      id
    }
  })
}
// 未通过审核并添加原因
export const isAuditAddreasonAPI = ({ id, reason }) => {
  return request({
    method: 'post',
    url: '/admin/isauditreason',
    data: {
      id,
      reason
    }
  })
}

// 获取收藏的商品
export const getstarstoreAPI = () => {
  return request({
    method: 'get',
    url: '/admin//getstarstore'
  })
}
/**
 * 删除商品信息
 * @param {*} id
 * @returns Promise对象
 */
export const deletstoreinfoAPI = (id) => {
  return request({
    method: 'delete',
    url: '/admin/deletstoreinfo',
    data: {
      id
    }
  })
}

// 用户管理

/**
 * 获取全部用户信息
 * @returns Promise object
 */
export const getuserAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getalluserinfo'
  })
}

/**
 * 修改用户权限 - 管理员
 * @param {*} param0
 * @returns Promise object
 */
export const changeusertypetoadmin = (id) => {
  return request({
    method: 'post',
    url: '/admin/changeusertypetoadmin',
    data: {
      id
    }
  })
}

/**
 * 修改用户权限 - 用户
 * @param {*} param0
 * @returns Promise object
 */
export const changeusertypetouser = (id) => {
  return request({
    method: 'post',
    url: '/admin/changeusertypetouser',
    data: {
      id
    }
  })
}

/**
 * 删除用户信息
 * @param {*} id
 * @returns Promise object
 */
export const deleteuserAPI = (id) => {
  return request({
    method: 'delete',
    url: '/admin/deleteuser',
    data: {
      id
    }
  })
}

/**
 * 上传首页轮播图
 * @param {*} param0
 * @returns Promise Object
 */
export const uploadimageAPI = ({ img_url, img_describe }) => {
  return request({
    method: 'post',
    url: '/admin/uploadimg',
    data: {
      img_url,
      img_describe
    }
  })
}

/**
 * 删除轮播图信息
 * @param {*} param0
 * @returns Promise Object
 */
export const deleteimageAPI = (id) => {
  return request({
    method: 'delete',
    url: '/admin/deleteimages',
    data: {
      id
    }
  })
}

/**
 * 编辑轮播图
 * @param {*} param0
 * @returns Promise Object
 */
export const updateimageAPI = ({ id, img_url, img_describe }) => {
  return request({
    method: 'post',
    url: '/admin/updateimages',
    data: {
      id,
      img_url,
      img_describe
    }
  })
}

/**
 * 获取轮播图
 * @returns Promise Object
 */
export const getimageAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getimages'
  })
}

/**
 * 设置轮播图是否在首页显示
 * @param {*} img_show
 * @param {*} id
 * @returns Promise Object
 */
export const showimageAPI = (img_show, id) => {
  return request({
    method: 'post',
    url: '/admin/showimages',
    data: {
      img_show,
      id
    }
  })
}

/**
 * 获取首页轮播图
 * @returns Promise Object
 */
export const isShowimageAPI = () => {
  return request({
    method: 'get',
    url: '/admin/isshowimages'
  })
}
// 资讯管理
/**
 * 查询资讯信息
 * @returns promise Objeect
 */
export const getarticleAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getarticle'
  })
}

/**
 * 发布资讯信息
 * @param {*} param0
 * @returns Promise Object
 */
export const publisharticleAPI = ({ title, content, publish_img, publish_time }) => {
  return request({
    method: 'post',
    url: '/admin/publisharticle',
    data: {
      title,
      content,
      publish_img,
      publish_time
    }
  })
}

/**
 * 编辑资讯
 * @param {*} param0
 * @returns Promise Object
 */
export const changearticleAPI = ({ id, title, content, publish_img, publish_time }) => {
  return request({
    method: 'post',
    url: '/admin/changearticle',
    data: {
      id,
      title,
      content,
      publish_img,
      publish_time
    }
  })
}

/**
 * 删除资讯
 * @param {*} param0
 * @returns Promise Object
 */
export const deletearticleAPI = (id) => {
  return request({
    method: 'delete',
    url: '/admin/deletearticle',
    data: {
      id
    }
  })
}

// 根据id查询资讯
export const getarticledetailbyidAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/getarticledetailbyid',
    data: {
      id
    }
  })
}
// 获取收藏的资讯
export const getzixuncollectAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getstarzixu'
  })
}
// 增加阅读
export const addReadAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/addreadbyid',
    data: {
      id
    }
  })
}

// 增加点赞
export const addLikeAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/addlikebyid',
    data: {
      id
    }
  })
}

// 增加评论数
export const addCommentnumAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/addcommentbyid',
    data: {
      id
    }
  })
}

// 增加收藏
export const addCollectAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/addcollectbyid',
    data: {
      id
    }
  })
}

// 增加收获地址
export const addAddressAPI = ({ name, phone, address }) => {
  return request({
    method: 'post',
    url: '/admin/addaddress',
    data: {
      name,
      phone,
      address
    }
  })
}

// 获取收货地址
export const getAddressAPI = () => {
  return request({
    method: 'get',
    url: '/admin/getaddress'
  })
}

// 根据id获取收货地址
export const getAddressByidAPI = (id) => {
  return request({
    method: 'post',
    url: '/admin/getaddressbyid',
    data: {
      id
    }
  })
}

// 删除收货地址
export const deleteaddressAPI = (id) => {
  return request({
    method: 'delete',
    url: '/admin/deleteaddress',
    data: {
      id
    }
  })
}

// 添加商品评价
export const addCommentAPI = ({ store_id, content, comment_time, user_pic }) => {
  return request({
    method: 'post',
    url: '/admin/addcomment',
    data: {
      store_id,
      content,
      comment_time,
      user_pic
    }
  })
}

// 查询评论
export const getCommentAPI = (store_id) => {
  return request({
    method: 'post',
    url: '/admin/getcomment',
    data: {
      store_id
    }
  })
}
